﻿using DrSoftsFrame.Servers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace PreeRegisterDAL
{
    public class LocalPacsDAL
    {
        /// <summary>
        /// 查询PACS报告列表
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static DataSet GetLabReportListByTime(string sTime,string eTime)
        {
            try
            {
                StringBuilder sqlstr = new StringBuilder();
                sqlstr.Append("select * from v_jksx_sms t where 1 = 1 and studystatus = 70 ");
                sqlstr.Append($"and CONVERT(varchar(100), reporttime, 20) >= '{sTime}' ");
                sqlstr.Append($"and CONVERT(varchar(100), reporttime, 20) <= '{eTime}' ");
                sqlstr.Append("order by reporttime desc ");

                DataSet ds = DbHelperSqlServer.Query(sqlstr.ToString());
                if (ds == null || ds.Tables.Count < 1)
                {
                    return null;
                }
                ds.Tables[0].TableName = "LocalPacs_jksx_sms";
                return ds;
            }
            catch (Exception err)
            {
                throw;
            }
        }

        /// <summary>
        /// 查询PACS报告列表
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static DataSet GetLabReportListByAdnum(string sTime, string eTime,string adnum)
        {
            try
            {
                StringBuilder sqlstr = new StringBuilder();
                sqlstr.Append("select * from v_jksx_sms t where 1 = 1 and studystatus = 70 ");
                sqlstr.Append($"and patientinpatientid='{adnum}' ");
                sqlstr.Append($"and CONVERT(varchar(100), reporttime, 20) >= '{sTime}' ");
                sqlstr.Append($"and CONVERT(varchar(100), reporttime, 20) <= '{eTime}' ");
                sqlstr.Append("order by reporttime desc ");

                DataSet ds = DbHelperSqlServer.Query(sqlstr.ToString());
                if (ds == null || ds.Tables.Count < 1)
                {
                    return null;
                }
                ds.Tables[0].TableName = "LocalPacs_jksx_sms";
                return ds;
            }
            catch (Exception err)
            {
                throw;
            }
        }
    }
}
